package com.byxy.service.impl;

import com.byxy.dao.AdminGroupDao;
import com.byxy.model.AdminGroup;
import com.byxy.service.AdminGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
@Service
@Transactional
public class AdminGroupServiceImpl implements AdminGroupService {
    @Autowired
    private AdminGroupDao adminGroupDao;

    @Override
    public void save(AdminGroup adminGroup) {
        adminGroupDao.save(adminGroup);
    }

    @Override
    public void delete(Integer[] ids) {
        for (int id : ids) {
            adminGroupDao.delete(id);
        }
    }


    @Override
    public void update(AdminGroup adminGroup) {
        adminGroupDao.update(adminGroup);
    }

    @Override
    public AdminGroup get(Integer id) {
        return adminGroupDao.get(id);
    }

    @Override
    public List<AdminGroup> listPage(Integer pageNum, Integer pageSize, String search) {
        return adminGroupDao.listPage(pageNum, pageSize, search);
    }

    @Override
    public Integer count(String search) {
        return adminGroupDao.count(search);
    }

    @Override
    public void enable(Integer[] ids) {
        for (int id : ids) {
            AdminGroup adminGroup = adminGroupDao.get(id);
            adminGroup.setStatus(true);
            adminGroupDao.update(adminGroup);
        }
    }

    @Override
    public void disable(Integer[] ids) {
        for (int id : ids) {
            AdminGroup adminGroup = adminGroupDao.get(id);
            adminGroup.setStatus(false);
            adminGroupDao.update(adminGroup);
        }
    }
}
